<?php

namespace app\api\controller;

use app\api\model\Applepay AS ApplepayModel;

use app\common\controller\Send;
use think\Request;

class Applepay 
{
    
    
    use Send;
    /**
     * 苹果内购验证
     * @return array
     * @throws \think\Exception\DbException
     */
    public function notify()
    {
        $reqData = input('');
        $this->debugLog('appData='.var_export($reqData));
        $return  = ApplepayModel::notify($reqData); 
        return self::sendResult($return['code'], $return['data'], $return['msg']);
    }
    
    
    public  function debugLog($msg) {
        $fileName = "debug_" . date('Ymd', time()) . ".log";
        $this->writeLog($msg, $fileName);
    }
    
    
    
    public function writeLog($msg, $fileName) {
        $filePath = '/data/web/xyz.leaf-tech.net/logs/';
        $file = $filePath . $fileName;
        if (!file_exists($filePath)) {
            mkdir($filePath, '0777', true);
        }
        if (is_writable(dirname($file))) {
            if (!is_string($msg)) {
                $msg = var_export($msg, TRUE);
            }
            file_put_contents($file, "#" . date('Y-m-d H:i:s') . $msg . "\r\n", FILE_APPEND);
        }
    }
    
}